package com.liush.srb.core.controller.api;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liush.srb.base.result.ResponseVo;
import com.liush.srb.core.hfb.RequestHelper;
import com.liush.srb.core.pojo.entity.UserBind;
import com.liush.srb.core.pojo.entity.UserInfo;
import com.liush.srb.core.service.UserBindService;
import com.liush.srb.core.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: liush
 * @CreateTime: 2023-04-04  20:42
 * @Description: 用户绑定表 前端控制器
 */
@RestController
@Slf4j
@Api(tags = "用户绑定表")
@RequestMapping("/api/core/userBind")
public class ApiUserBindController {

    @Resource
    UserInfoService userInfoService;
    @Resource
    UserBindService userBindService;

    @ApiOperation("hfb用户绑定模块")
    @PostMapping("bind")
    public ResponseVo bindHfb(@RequestHeader(value = "token", required = false) String token,
                              @RequestBody UserBind userBind) {
        //业务方法：将页面收集的表单数据和服务器中的数据 构建成一个自动提交的表单
        //  让浏览器将参数提交到hfb实现srb账号和hfb账户绑定
        String formStr = userBindService.bindHfb(userBind, token);
        return ResponseVo.ok().data("form", formStr);
    }

    ///api/core/userBind/notify
    @ApiOperation("hfb用户绑定成功异步回调")
    @PostMapping("notify")
    public String hfbNotify(HttpServletRequest request) {
        return userInfoService.hfbNotify(request);
    }
}
